<template>
    <div id="box">
            <ul id="con1" ref="con1" :class="{anim:animate==true}">
                <li v-for='(item,index) in items' :key="index">
                    <!-- <span>高风险</span> -->
                    <span>{{item.name}}</span>
                    <span>{{item.area}}</span>
                    <span>{{item.percentage}}</span>
                </li>
            </ul>
        </div>
</template>
<script>
export default {
data() {
  return {
      animate:false,
      items:[
          {name:"无锡莲花公司1",area:"新吴区",percentage:"60%"},
          {name:"无锡莲花公司2",area:"新吴区",percentage:"60%"},
          {name:"无锡莲花公司3",area:"新吴区",percentage:"60%"},
           {name:"无锡莲花公司4",area:"新吴区",percentage:"60%"},
          {name:"无锡莲花公司5",area:"新吴区",percentage:"60%"},
          {name:"无锡莲花公司6",area:"新吴区",percentage:"60%"},
           {name:"无锡莲花公司7",area:"新吴区",percentage:"60%"},
          {name:"无锡莲花公司8",area:"新吴区",percentage:"60%"},
          {name:"无锡莲花公司9",area:"新吴区",percentage:"60%"},
      ]
  } 
},
props:{

},
created(){
      setInterval(this.scroll,1000)
},
methods: {
    scroll(){
       this.animate=true;    // 因为在消息向上滚动的时候需要添加css3过渡动画，所以这里需要设置true
       setTimeout(()=>{      //  这里直接使用了es6的箭头函数，省去了处理this指向偏移问题，代码也比之前简化了很多
               this.items.push(this.items[0]);  // 将数组的第一个元素添加到数组的
               this.items.shift();               //删除数组的第一个元素
               this.animate=false;  // margin-top 为0 的时候取消过渡动画，实现无缝滚动
       },500)
    }
}
}
</script>
<style lang="scss" scoped>
#box{
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding:0 20px;
    box-sizing: border-box;
}
.anim{
    transition: all .5s;
    margin-top: -10%;
}
#con1{
    height:100%;
}
#con1 li{
    list-style: none;
    display:flex;
    justify-content: space-between;
    align-items: center;
    height: 20%;
    //span{
        // &:nth-child(1){
        //     padding:5px 10px;
        //     background:#fff;
        //     color:#000;
        //     border-radius:2px;
        //     font-size:14px;
        // }
   // }
}
</style>